<div class="side-search">
    <form class="layui-form">
        <div class="layui-inline">
            <input class="layui-input" name="word" type="text" placeholder="请输入关键词">
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </div>
    </form>
</div>

<script>
    layui.use(function () {
        let form = layui.form;
        form.on('submit(search)', (data) => {
            let field = data.field;
            let route = '{{ current_route }}' ? '{{ current_route }}' : 'post'
            window.location.href = `/blog/${route}_search?word=${field.word}`
            return false; // 阻止默认 form 跳转
        });
    });
</script>